{extend name="admin/base" /}
{block name="resources"/}
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/product.css">
<style type="text/css">
.fun-a {
	margin-top: 0px;
	padding: 6px 15px 0 15px;
}
.style0list tbody td a{
	margin-left: 8px;
}
.num{width:40px;text-align:center;}	
.cell_total{text-overflow:ellipsis;white-space:nowrap;overflow:hidden;width:250px;display: block;}
.style0list table input {
	margin-bottom: 0px;
}

.style0list table input.sort {
	width: auto;
	text-align: center;
}

.style0list tbody td {
	line-height: 28px;
}
</style>
{/block}
{block name="right_tab"}
<li><a class="nscs-table-handle_green" href="{:__URL('ADMIN_MAIN/config/addhelpclass')}" ><i class="fa fa-plus-circle"></i>&nbsp;添加帮助类型</a></li>
{/block}
{block name="main"}
<div class="mod-table">
	<div class="con style0list">
		<table>
			<colgroup>
				<col style="width: 1%">
				<col style="width: 8%;">
				<col style="width: 15%;">
				<col style="width: 20%;">
				<col style="width: 10%;">
				<col style="width: 20%;">
				<col style="width:auto">
			</colgroup>
			<thead>
				<tr align="center">
					<th><label><input value="" name="" id="ckall" type="checkbox" onClick="CheckAll()"></label></th>
					<th class="x-tab"><div class="iconbg-arrow up">排序</div></th>
					<th class="x-tab tal"><div class="iconbg-arrow up">类型名称</div></th>
					<th class="x-tab">操作</th>
				</tr>
			</thead>
			<tbody id="linkList"></tbody>
		</table>
	</div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
$(function(){
	$("#linkList input[type='number']").live("keyup",function(){
		if($(this).val().length>0){
			var reg = /^[0-9]+$/;
			if(!reg.test($(this).val())){
				$(this).val(0);
			}
			if($(this).val().indexOf(".")>-1){
				$(this).val(0);
			}
		}
	});
});
//全选
function CheckAll(){
	if($("#linkList input[type = 'checkbox']").attr("checked")){
		$("#linkList input[type = 'checkbox']").attr("checked",false);
	}else{
		$("#linkList input[type = 'checkbox']").attr("checked",true);
	}
}

//分页数据
function LoadingInfo(page_index) {
	var search_text = $("#search_text").val();
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/config/helpclass')}",
		data : {
			"page_index" : page_index, "page_size" : $("#showNumber").val()
		},
		success : function(data) {
			var html = '';
			if (data["data"].length > 0) {
				for (var i = 0; i < data["data"].length; i++) {
					html += '<tr align="center">';
					html += '<td><div class="cell"><label ><input name="sub" type="checkbox" value="'+ data['data'][i]['class_id']+'"></label></div></td>';
					html += '<td><input type="number" min="0" value="'+ data["data"][i]["sort"]+'"  nav_id="'+ data['data'][i]['class_id']+'" class="num" onchange="updateClass('+i+','+data["data"][i]["class_id"]+')" id="sort'+i+'"></td>';
					html += '<td class="tal"><input type="text" id="class_name'+i+'" value="' + data["data"][i]["class_name"]+ '"onchange="updateClass('+i+','+data["data"][i]["class_id"]+')" /></td>';
					html += '<td><a style="cursor: pointer;" onclick="deleteClass('+data['data'][i]['class_id']+')">删除</a></td>';
					//html += '<td><a href="ADMIN_MAIN/config/updatelink?link_id='+ data['data'][i]['link_id']+'">修改</a></td> ';
					html += '</tr>';
				}
			} else {
				html += '<tr align="center"><th colspan="9">暂无帮助类型</th></tr>';
			}
			$(".style0list tbody").html(html);
			initPageData(data["page_count"],data['data'].length,data['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
		}
	});
}	

/*
*修改input值
*/
function updateClass(index,class_id){
	var class_name = $("#class_name"+index).val();
	var sort = $("#sort"+index).val();
	$.ajax({
		type:"post",
		url:"{:__URL('ADMIN_MAIN/config/updateclass')}",
		data:{'class_name':class_name,'sort':sort,"class_id":class_id},
		async:true,
		success: function (data) {
			var flag = "error";
			if(data.code>0){
				flag = "success";
			}
			showTip(data['message'],flag);
		}
	});
}
/*
*删除分类
*/
function deleteClass(class_id){
	$( "#dialog" ).dialog({
        buttons: {
            "确定": function() {
                $(this).dialog('close');
                $.ajax({
        			type : "post",
        			url: "{:__URL('ADMIN_MAIN/config/classdelete')}",
        			async : true,
        			data: { "class_id": class_id},
        			success : function(data) {
        				//alert(JSON.stringify(data));return false;
        				if(data["code"] > 0 ){
        					showMessage('success', data["message"],"{:__URL('ADMIN_MAIN/config/helpclass')}");
        				}else{
        					showMessage('error', data["message"]);
        				}
        			}
        		});
            },
            "取消,#e57373": function() {
                $(this).dialog('close');
            }
        },
        contentText:"你确定删除该分类以及该分类下所有内容吗？",
        title:"消息提醒"
    });
}
</script>
{/block}